<template>
  <div class="my-param-val-maintain-table-submitform">
    <!-- 新增修改表单 -->
    <el-dialog
      width="50%"
      :title="textMap[dialogStatus]"
      :visible.sync="DialogFormVisibleCom"
      append-to-body
    >
      <el-form ref="dataForm" :rules="rules" :model="formSubmitDataCom" label-position="right" label-width="100px"
               style="width: 90%; margin:10px auto;">

        <el-row :gutter="20">
          <el-col :span="12">
            <!-- 调整项编码 -->
            <el-form-item label="调整项编码" prop="adj_code">
              <el-input v-model="formSubmitDataCom.adj_code" :disabled="true"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!-- 转移曲线： -->
            <el-form-item label="调整项名称" prop="adj_name">
              <el-input v-model="formSubmitDataCom.adj_name" :disabled="true"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!-- 转移曲线： -->
            <el-form-item label="调整项类型" prop="adj_type">
              <el-input v-model="formSubmitDataCom.adj_type" :disabled="true"/>
            </el-form-item>
          </el-col>
          
          <el-col :span="12">
            <!-- 所属法人 -->
            <el-form-item label="所属法人" prop="lp_code">
              <el-select v-model="formSubmitDataCom.lp_code" class="filter-item" placeholder="Please select"
                         :disabled="true">
                <el-option v-for="item in lpOptions" :key="item.lp_code" :label="item.lp_name" :value="item.lp_code"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!-- 生效日期 -->
            <el-form-item label="生效日期" prop="s_date">
              <el-date-picker
                v-model="formSubmitDataCom.s_date"
                type="date"
                placeholder="Please pick a date"
                value-format="yyyy-MM-dd"
              />
            </el-form-item>

          </el-col>
          <el-col :span="12">
            <!-- 生效日期 -->
            <el-form-item label="失效日期" prop="e_date">
              <el-date-picker
                v-model="formSubmitDataCom.e_date"
                type="date"
                placeholder="Please pick a date"
                value-format="yyyy-MM-dd"
              />
            </el-form-item>

          </el-col>
          <el-col :span="12">
            <!-- 转移曲线： -->
            <el-form-item label="筛选条件（SQL代码）：" prop="sc_str">
              <el-input v-model="formSubmitDataCom.sc_str"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!-- 调整点差值： -->
            <el-form-item label="调整点差值：" prop="adj_value">
              <el-input v-model="formSubmitDataCom.adj_value"/>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!-- 调整单位： -->
            <el-form-item label="调整单位：" prop="adj_unit">
              <el-select v-model="formSubmitDataCom.adj_unit" class="filter-item" placeholder="Please select"
                         >
                <el-option v-for="item in adjUnit" :key="item.key" :label="item.display_name" :value="item.key"/>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <!-- 备注： -->
            <el-form-item label="备注：" prop="remark">
              <el-input v-model="formSubmitDataCom.remark"/>
            </el-form-item>
          </el-col>
        </el-row>


      </el-form>
      <div slot="footer" class="dialog-footer" style="text-align:center">
        <el-button @click="resetFormData">
          重置
        </el-button>
        <el-button type="primary" @click="dialogStatus==='create'?createData():updateData()">
          提交
        </el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// import PageHeaderLayout from '@/layouts/PageHeaderLayout'
// import ApeDrawer from '@/components/ApeDrawer'
// import { mapGetters } from 'vuex'
const adjUnit = [
  { key: '1', display_name: '%' },
  { key: '2', display_name: 'BP' },
]


export default {
  name: 'submitForm',
  components: {
    //PageHeaderLayout,
  },
  props: {
    dialogFormVisible: {
      type: Boolean,
      default: false
    },
    dialogStatus: {
      type: String,
    },
    // tableColumn: {
    //     type: Array,
    //     default() {
    //         return []
    //     }
    // },
    formSubmitData: {
      type: Object,
      default: function () {
        return {}
      }
    },
    // 法人selectData
    lpOptions: {
      type: Array
    },

  },
  // 定义属性
  data() {

    return {
      textMap: {
        update: '修改',
        create: '新增'
      },
      rules: {
        s_date: [{required: true, message: '生效日期必填', trigger: 'change'}],
        e_date: [{required: true, message: '失效日期必填', trigger: 'change'}],
        sc_str: [{required: true, message: '筛选条件（SQL代码）必填', trigger: 'change'}],
        adj_value: [{required: true, message: '调整点差值必填', trigger: 'change'}],
        adj_unit: [{required: true, message: '调整单位必填', trigger: 'change'}],
        // type: [{ required: true, message: 'type is required', trigger: 'change' }],
        // timestamp: [{ type: 'date', required: true, message: 'timestamp is required', trigger: 'change' }],
        // title: [{ required: true, message: 'title is required', trigger: 'blur' }]
      },
      // 表单用到的值
      adjUnit,
      // statusOptions: ['published', 'draft', 'deleted'],
    }
  },
  // 计算属性，会监听依赖属性值随之变化
  computed: {
    DialogFormVisibleCom: {
      get() {
        return this.dialogFormVisible
      },
      set(val) {
        this.$emit('update:dialogFormVisible', val)
      }
    },
    formSubmitDataCom: {
      get() {
        return this.formSubmitData
      },
      set(val) {
        this.$emit('update:formSubmitData', val)
      }
    }
  },
  // 监控data中的数据变化
  watch: {},
  // 方法集合
  methods: {
    resetFormData() {

      let exclude = [
        'lp_code',
        'adj_type',
        'adj_name',
        'adj_code'
      ]
      this.$emit('resetFormDataEmit', {
        exclude,
      })
    },
    findlp() {
      this.$refs['datalp'].validate((valid) => {
        if (valid) {
          this.$emit('findlp')
          // this.temp.id = parseInt(Math.random() * 100) + 1024 // mock a id
          // this.temp.author = 'vue-element-admin'
          // createArticle(this.temp).then(() => {
          //   this.list.unshift(this.temp)
          //   this.dialogFormVisible = false
          //   this.$notify({
          //     title: 'Success',
          //     message: 'Created Successfully',
          //     type: 'success',
          //     duration: 2000
          //   })
          // })
        }
      })
    },
    createData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$emit('handleFromCreateDataEmit')
          this.$delete(this.formSubmitData, "adj_code");
          this.$delete(this.formSubmitData, "adj_name");
          // this.$delete(this.formSubmitData, "adj_type");
          // this.temp.id = parseInt(Math.random() * 100) + 1024 // mock a id
          // this.temp.author = 'vue-element-admin'
          // createArticle(this.temp).then(() => {
          //   this.list.unshift(this.temp)
          //   this.dialogFormVisible = false
          //   this.$notify({
          //     title: 'Success',
          //     message: 'Created Successfully',
          //     type: 'success',
          //     duration: 2000
          //   })
          // })
        }
      })
    },

    updateData() {
      this.$refs['dataForm'].validate((valid) => {
        if (valid) {
          this.$delete(this.formSubmitData, "_XID");
          this.$delete(this.formSubmitData, "lp_name");
          this.$delete(this.formSubmitData, "adj_code");
          this.$delete(this.formSubmitData, "adj_name");
          this.$delete(this.formSubmitData, "adj_type");
          this.$delete(this.formSubmitData, "lp_code");
          // const tempData = Object.assign({}, this.formSubmitData)
          this.$emit('handleFromUpdateDataEmit')
          // tempData.timestamp = +new Date(tempData.timestamp) // change Thu Nov 30 2017 16:41:05 GMT+0800 (CST) to 1512031311464
          // updateArticle(tempData).then(() => {
          //   const index = this.list.findIndex(v => v.id === this.temp.id)
          //   this.list.splice(index, 1, this.temp)
          //   this.dialogFormVisible = false
          //   this.$notify({
          //     title: 'Success',
          //     message: 'Update Successfully',
          //     type: 'success',
          //     duration: 2000
          //   })
          // })
        }
      })
    },
    

  },
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {

  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {

  },
  beforeCreate() {
  }, // 生命周期 - 创建之前
  beforeMount() {
  }, // 生命周期 - 挂载之前
  beforeUpdate() {
  }, // 生命周期 - 更新之前
  updated() {
  }, // 生命周期 - 更新之后
  beforeDestroy() {
  }, // 生命周期 - 销毁之前
  destroyed() {
  }, // 生命周期 - 销毁完成
  activated() {
  }, // 如果页面有keep-alive缓存功能，这个函数会触发
}
</script>

<style lang='scss' scoped>
.my-param-val-maintain-table-submitform {
  ::v-deep {
    .el-date-editor.el-input, .el-date-editor.el-input__inner {
      width: 100% !important;
    }
  }
}


</style>